﻿// Copyright © Microsoft Corporation.  All Rights Reserved.
// This code released under the terms of the 
// Microsoft Public License (MS-PL, http://opensource.org/licenses/ms-pl.html.)

namespace Microsoft.Expression.Prototyping.Mockups.Design
{
#if SILVERLIGHT
	extern alias Silverlight;
	using SolidColorBrush = Silverlight::System.Windows.Media.SolidColorBrush;
	using Visibility = Silverlight::System.Windows.Visibility;
	using Color = Silverlight::System.Windows.Media.Color;
	using Brush = Silverlight::System.Windows.Media.Brush;
	using FrameworkElement = Silverlight::System.Windows.FrameworkElement;
#else
	using SolidColorBrush = System.Windows.Media.SolidColorBrush;
	using Visibility = System.Windows.Visibility;
	using Color = System.Windows.Media.Color;
	using Brush = System.Windows.Media.Brush;
	using FrameworkElement = System.Windows.FrameworkElement;
#endif

	using System.Collections.Generic;
	using System.ComponentModel;
	using Microsoft.Windows.Design;

	internal abstract class DialogMockupExample : Microsoft.Expression.Drawing.Design.ToolboxExample<DialogMockup>
	{
		protected static Color BaseBackgroundColor
		{
			get
			{
				return Color.FromArgb(0xFF, 0xFF, 0xFF, 0xFF);
			}
		}

		protected static Color BaseBorderColor
		{
			get
			{
				return Color.FromArgb(0xFF, 0x60, 0x60, 0x60);
			}
		}
		
		protected static DialogMockup CreateInstance(IconImage iconImage, double width, double height, Visibility? showButton1, Visibility? showButton2, Visibility? showButton3)
		{
			return CreateInstance(iconImage, width, height, null, null, showButton1, showButton2, showButton3, null, null, null, null);
		}

		protected static DialogMockup CreateInstance(IconImage iconImage, double width, double height, Visibility? showButton1, Visibility? showButton2, Visibility? showButton3, Visibility? showMinimizeButton)
		{
			return CreateInstance(iconImage, width, height, null, null, showButton1, showButton2, showButton3, showMinimizeButton, null, null, null);
		}

		protected static DialogMockup CreateInstance(
			IconImage iconImage,
			double? width, double? height,
			Brush background, Brush borderBrush,
			Visibility? showButton1, Visibility? showButton2, Visibility? showButton3,
			Visibility? showMinimizeButton,
			Visibility? showMaximizeButton,
			Visibility? showFullScreenButton,
			Visibility? showCloseButton)
		{
			DialogMockup dialogMockup = new DialogMockup();
			dialogMockup.IconImage = iconImage;

			if (width.HasValue)
			{
				dialogMockup.Width = width.Value;
			}
			else
			{
				dialogMockup.Width = 300;
			}

			if (height.HasValue)
			{
				dialogMockup.Height = height.Value;
			}
			else
			{
				dialogMockup.Height = 100;
			}

			if (background != null)
			{
				dialogMockup.Background = background;
			}
			else
			{
				dialogMockup.Background = new SolidColorBrush(BaseBackgroundColor);
			}

			if (borderBrush != null)
			{
				dialogMockup.BorderBrush = borderBrush;
			}
			else
			{
				dialogMockup.BorderBrush = new SolidColorBrush(BaseBorderColor);
			}

			if (showButton1.HasValue)
			{
				dialogMockup.ShowButton1 = showButton1.Value;
			}
			else
			{
				dialogMockup.ShowButton1 = Visibility.Collapsed;
			}

			if (showButton2.HasValue)
			{
				dialogMockup.ShowButton2 = showButton2.Value;
			}
			else
			{
				dialogMockup.ShowButton2 = Visibility.Collapsed;
			}

			if (showButton3.HasValue)
			{
				dialogMockup.ShowButton3 = showButton3.Value;
			}
			else
			{
				dialogMockup.ShowButton3 = Visibility.Collapsed;
			}

			if (showMinimizeButton.HasValue)
			{
				dialogMockup.ShowMinimizeButton = showMinimizeButton.Value;
			}
			else
			{
				dialogMockup.ShowMinimizeButton = Visibility.Collapsed;
			}

			if (showMaximizeButton.HasValue)
			{
				dialogMockup.ShowMaximizeButton = showMaximizeButton.Value;
			}
			else
			{
				dialogMockup.ShowMaximizeButton = Visibility.Collapsed;
			}

			if (showCloseButton.HasValue)
			{
				dialogMockup.ShowCloseButton = showCloseButton.Value;
			}
			else
			{
				dialogMockup.ShowCloseButton = Visibility.Visible;
			}

			if (showFullScreenButton.HasValue)
			{
				dialogMockup.ShowFullScreenButton = showFullScreenButton.Value;
			}
			else
			{
				dialogMockup.ShowFullScreenButton = Visibility.Collapsed;
			}

			dialogMockup.ClearValue(FrameworkElement.StyleProperty);

			return dialogMockup;
		}
	}

	internal class ThreeButtonDialogMockup : DialogMockupExample
	{
		public ThreeButtonDialogMockup()
		{
			this.DisplayName = "ThreeButtonDialogMockup";
			this.ExampleInstance = () =>
			{
					return CreateInstance(IconImage.Warning, 450, 200, Visibility.Visible, Visibility.Visible, Visibility.Visible);
			};
		}
	}

	internal class TwoButtonDialogMockup : DialogMockupExample
	{
		public TwoButtonDialogMockup()
		{
			this.DisplayName = "TwoButtonDialogMockup";
			this.ExampleInstance = () =>
			{
					return CreateInstance(IconImage.Warning, 450, 200, Visibility.Collapsed, Visibility.Visible, Visibility.Visible);
			};
		}
	}

	internal class OneButtonDialogMockup : DialogMockupExample
	{
		public OneButtonDialogMockup()
		{
			this.DisplayName = "OneButtonDialogMockup";
			this.ExampleInstance = () =>
			{
					return CreateInstance(IconImage.Warning, 450, 200, Visibility.Visible, Visibility.Collapsed, Visibility.Collapsed, Visibility.Visible);
			};
		}
	}

	internal sealed class DialogMockupExampleFactory : IToolboxExampleFactory
	{
		private static List<IToolboxExample> examples;
		public IEnumerable<IToolboxExample> Examples
		{
			get
			{
				if (DialogMockupExampleFactory.examples == null)
				{
					DialogMockupExampleFactory.examples = new List<IToolboxExample>()
					{
						new ThreeButtonDialogMockup(),
						new TwoButtonDialogMockup(),
						new OneButtonDialogMockup()
					};
				}

				return DialogMockupExampleFactory.examples;
			}
		}
	}
}
